package graph.editor;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.RectangularShape;
import java.util.Observer;

public class IniVertex extends Vertex {
	RectangularShape shape;
	String label;
	// Color vcolor;
	private static final Point2D DELTA_LABEL = new Point(1, -1);
	static boolean fin = false;
	static boolean initi = true;

	IniVertex(RectangularShape rs, String label, Color color,boolean initi, boolean fin) {
		super(rs, label, color, initi, fin);
		// this.vcolor=color;
		this.shape = rs;
		this.label = label;
		this.initi = initi;
		this.fin = fin;
	}

	public boolean contains(int x, int y) {
		return shape.contains(x, y);
	}

	public void draw(Graphics2D g2) {
		g2.setColor(this.vColor);
		g2.fill(shape);

		if (label != null)
			g2.drawString(label, (int) (shape.getMaxX() + DELTA_LABEL.getX()),
					(int) (shape.getMinY() + DELTA_LABEL.getY()));
		Graphics2D g = (Graphics2D) g2.create();

		// double dx = x2 - x1, dy = y2 - y1;
		double angle = Math.atan2(shape.getCenterX(), shape.getCenterY());
		int len = (int) Math.sqrt(1000);
		AffineTransform at = AffineTransform.getTranslateInstance(
				shape.getCenterX() - 55, shape.getCenterY());
		// at.concatenate(AffineTransform.getRotateInstance(angle));
		g.transform(at);

		// Draw horizontal arrow starting in (0, 0)
		g.drawLine(len, 0, len - 30, 0);
		g.fillPolygon(new int[] { len, len - 4, len - 4, len }, new int[] { 1,
				-4, 4, 0 }, 4);
		if (fin == true) {
			Graphics2D g1 = (Graphics2D) g2.create();
			double angle1 = Math.atan2(shape.getCenterX(), shape.getCenterY());
			int len1 = (int) Math.sqrt(1000);
			AffineTransform at1 = AffineTransform.getTranslateInstance(
					shape.getCenterX() + 22, shape.getCenterY());
			g1.transform(at1);
			g1.drawLine(len1, 0, len1 - 30, 0);
			g1.fillPolygon(new int[] { len1, len1 - 4, len1 - 4, len1 },
					new int[] { 1, -4, 4, 0 }, 4);
		}
	}

}
